#include <SDL.h>
#include "controller.h"

Controller::Controller() : model() {
  SDL_WM_SetCaption( ParseXML::getInstance()->getXmlString("app_name").c_str(), NULL );
}

Controller::~Controller() {
  atexit(SDL_Quit);
  //relsease the ParseXML
  if(ParseXML::getInstance()){
	   delete ParseXML::getInstance();
   }
}

void Controller::play() {
  SDL_Event event;

  bool done = false;
  while ( ! done ) {

    model.draw();
    model.update();

    SDL_PollEvent(&event);
    Uint8 *keystate = SDL_GetKeyState(NULL);
    switch (event.type) {
      case SDL_QUIT: {
        done = true;
        break;
      }
      case SDL_KEYDOWN: {
        if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) {
          done = true;
        }
        if (keystate[SDLK_UP]) {
        }
        if (keystate[SDLK_DOWN]) {
        }
        break;
      }
    }
  }
}
